;;;  cmake.el ---- 与 cmake 相关的设置

;; cmake-mode
(require 'cmake-mode)

;; 設置啟用cmake-mode的文件
(setq auto-mode-alist
      (append '(("CMakeLists\\.txt'" . cmake-mode)
		("\\.cmake\\'" . cmake-mode))
	      auto-mode-alist))

(autoload 'cmake-font-lock-activate "cmake-font-lock" nil t)
(add-hook 'cmake-mode-hook 'cmake-font-lock-activate)

;; 改變 CMakeLists.txt 文件 buffer 的默認命名，
;; 使其以 cmake-<directory name> 的方式命名
(when (load "uniquify" 'NOERROR)
  (require 'uniquify)
  (setq uniquify-buffer-name-style 'forward)
  ;; (setq uniquify-buffer-name-style 'post-forward)
  )
(defun cmake-rename-buffer ()
  "Renames a CMakeLists.txt buffer to cmake-<directory name>."
  (interactive)
  ;; (print (concat "buffer-filename = " (buffer-file-name)))
  ;; (print (concat "buffer-name     = " (buffer-name)))
  (let (parent-dir new-buffer-name)
    (when (and (buffer-file-name)
	       (string-match "CMakeLists.txt" (buffer-name)))
      ;; (setq file-name (file-name-nondirectory (buffer-file-name)))
      (setq parent-dir (file-name-nondirectory
			(directory-file-name (file-name-directory
					      (buffer-file-name)))))
      ;; (print (concat "parent-dir = " parent-dir))
      (setq new-buffer-name (concat "cmake-" parent-dir))
      ;; (print (concat "new-buffer-name= " new-buffer-name))
      (rename-buffer new-buffer-name t)
      )
    )
  )

(add-hook 'cmake-mode-hook (function cmake-rename-buffer))


(require 'cpputils-cmake)
(add-hook 'c-mode-common-hook
	  (lambda ()
	    (if (derived-mode-p 'c-mode 'c++-mode)
		(cppcm-reload-all))))
(global-set-key (kbd "C-c C-g")
		'(lambda ()
		   (interactive)
		   (gud-gdb (concat "gdb --fullname "
				    (cppcm-get-exe-path-current-buffer)))))
;; OPTIONAL, specify extra flags forwarded to compiler
;; (setq cppcm-extra-preprocss-flags-from-user '("-I/usr/src/linux/include" "-DNDEBUG"))


;;; cmake.el ends here


